package first.codeTop.byteDance;

/**
 * @ClassName Leetcode415
 * @description:
 * @author: 荣燊
 * @create: 2021-07-26 10:18
 **/
public class Leetcode415 {
    // 字符串相加
    public static void main(String[] args) {
        String num1 = "1002321";
        String num2 = "9997679";
        System.out.println(addStrings(num1, num2));
    }

    public static String addStrings(String num1, String num2) {
        StringBuilder stringBuilder = new StringBuilder();
        char[] numc1 = num1.toCharArray();
        char[] numc2 = num2.toCharArray();
        int flag = 0;
        int i = numc1.length-1;
        int j = numc2.length-1;
        while (i>=0 || j>=0 || flag != 0) {
            if (i >= 0) {
                flag += numc1[i--] - '0';
            }
            if (j >= 0) {
                flag += numc2[j--] - '0';
            }
            stringBuilder.append(flag%10);
            flag /= 10;
        }
        return stringBuilder.reverse().toString();
    }
}
